console.log(23233);
// æ¶ˆæ¯å¼¹çª—
// App.dialog = {};
dialog_show = function() {
    /*
    * App.dialog.show('notice', 'è¯·é€‰æ‹© '+noticeChecked, [], 3000);*/
    dialog_close();
    var type = arguments[0] ? arguments[0] : 'notice';
    var desc = arguments[1] ? arguments[1] : 'è¯·æ£€æŸ¥æ‚¨è®¿é—®çš„ç½‘å€æ˜¯å¦æ­£ç¡®ï¼Œå¦‚æœ‰ä»»ä½•æ„è§æˆ–å»ºè®®ï¼Œè¯·åŠæ—¶åé¦ˆç»™æˆ‘ä»¬ã€‚';
    var btns = arguments[2] ? arguments[2] : [];
    var time = arguments[3] ? arguments[3] : 0;
    var url = arguments[4] ? arguments[4] : '';
    var mask = $('<div />').addClass('mask');
    var icon = $('<i />').addClass('icon');
    if (type && type != 'notice') {
        icon.addClass('icon_'+type);
    }

    var msg = $('<p />').html(desc);
    var content = $('<div />').addClass('content').append(icon).append(msg);
    if (btns.length) {
        var btn_area = $('<p />').addClass('btns');
        for(var i in btns) {
            var btn = $('<a />').addClass('btn').addClass('btn_' + i).attr('href', btns[i].href);
            if (btns[i].click) {
                btn.attr('onclick', btns[i].click);
            }
            btn.text(btns[i].name).appendTo(btn_area);
        }
        content.append(btn_area);
    }
    $('<div />').addClass('page-dialog').append(mask).append(content).appendTo($('body'));

    if (time > 0) {
        setTimeout(function(){
            dialog_close();
            if(url != ''){
                window.location.href =url;
            }
        }, time);
    }
}
dialog_close = function() {
    $('.page-dialog').remove();
}

// å›žåˆ°é¡¶éƒ¨--æ”¾åœ¨é¡µé¢ä¸Š
$('.app-go-top').off().on('click', function(e) {

    $('html, body').scrollTop(0);
    e.preventDefault();
});
// æ‰“å¼€ä¼˜æƒ é€‰é¡¹
couponOpen = function(target) {
    $('#'+target).addClass('show');
}

// å…³é—­ä¼˜æƒ é€‰é¡¹
couponClose = function(target) {
    $('#'+target).removeClass('show');
}
// é¡µé¢æ»šåŠ¨ç›¸å…³
$(document).on('scroll', function() {

    var scrollTop = document.documentElement.scrollTop | document.body.scrollTop;

    // æ»‘åŠ¨åˆ°åº•åŠ è½½æ›´å¤š
    var iElem = $('.content-list');
    if (iElem.length) {
        var cHeight = window.innerHeight;
        var iHeight = $(document).height();
        var iPosition = iElem.position().top;

        var tHeight = scrollTop + iPosition;
        if (cHeight + scrollTop + 50 > iHeight) {
            loadmore();
        }
    }

    // å›žåˆ°é¡¶éƒ¨
    var iGoTop = $('.app-go-top');
    if (iGoTop.length) {
        if (scrollTop > 300) {
            if (!iGoTop.hasClass('show')) {
                iGoTop.addClass('show');
            }
        } else {
            iGoTop.removeClass('show');
        }
    }

    // äº§å“é¡µé¢åˆ‡æ¢ç½®é¡¶
    var sticky = $('#header-sticky');
    var fiexd = $('#sticky-warp');
    if (sticky.length && fiexd.length) {
        scrollTop >= sticky.offset().top ? fiexd.addClass('fixed') : fiexd.removeClass('fixed');
    }
});
// åŠ è½½æ›´å¤šé¡µ
loadmore = function() {
    if (page <=pages) {
        if (!$('.page-content').find('.loading-more').length) {
            $('<div />').addClass('loading-more').html('<i></i>').appendTo($('.page-content'));
            ajax_goods();
        }
    }
}
function ajaxsecrch(){
    let keyword = $.trim($('.header-search-txt').val());

    $(".header-search-frm").submit();
    /*if(keyword != ''){
        $(".header-search-frm").submit();
    }else {
        dialog_show('fail', "è¯·è¾“å…¥æœç´¢å…³é”®å­—", [], 3000);
    }*/
    return false;
}

// çœå¸‚åŒºè”åŠ¨é€‰æ‹©
regionSelect = function(elem, region_type, region_id) {
    var province_input = $('#m-addr-mask').find("input[name='province']");
    var city_input = $('#m-addr-mask').find("input[name='city']");
    var district_input = $('#m-addr-mask').find("input[name='district']");
    var seclet_text = $('<span />').text('è¯·é€‰æ‹©');

    switch(region_type) {
        case 2:
            if (!$(elem).hasClass('region-active')) {
                $('.mars-ph-province').removeClass('mars-ph-active').html($(elem).html());
                $('.mars-ph-city').addClass('mars-ph-active').html(seclet_text).css('display', 'inline-block');
                $('.mars-ph-district').html('').css('display', 'none');
            }
            province_input.val(region_id);
            break;
        case 3:
            if (!$(elem).hasClass('region-active')) {
                $('.mars-ph-city').removeClass('mars-ph-active').html($(elem).html()).css('display', 'inline-block');
                $('.mars-ph-district').addClass('mars-ph-active').html(seclet_text).css('display', 'inline-block');
            }
            city_input.val(region_id);
            break;
        case 4:
            $('.mars-ph-district').html($(elem).html());
            district_input.val(region_id);
            break;
        default:
            break;
    }

    $(elem).parent().children().removeClass('region-active');
    $(elem).addClass('region-active');

    if (region_type == 4) {
        $('#region-selector').hide();
        $('.m-addr-region').html($('.mars-ph-province').html() + $('.mars-ph-city').html() + $('.mars-ph-district').html());
        return;
    }
    $.get("/home/api/getRegion.html", {"parent_id":region_id}, function (data) {
        var res = JSON.parse(data);
        var target = $('#region-selector-list-' + region_type);
        console.log("target= "+region_type);
        let datas = res.data;
        let html = '';
        if(datas.length > 0){
            for(var index in datas) {
                let num = datas[index].level+1;
                html +='<li onclick="javascript:regionSelect(this, '+num+', '+datas[index].id+');"><span>'+datas[index].name+'</span></li>';
            }
        }
        if (target.length && html) {
            target.html(html);
            $('.mars-regions').children().hide();
            target.show();
        }
        return;
    })

    /*
    if (!$('#' + region_name).children().length) {
        $('.mars-regions').children().hide();
        $('#' + region_name).show();
    }
    */
}

// çœå¸‚åŒºåˆ‡æ¢
regionToggle = function(elem, list_id) {
    if (!$(elem).hasClass('mars-ph-active')) {
        $('.mars-panel-header').children().removeClass('mars-ph-active');
        $(elem).addClass('mars-ph-active');
        $('.mars-regions').children().hide();
        $('#region-selector-list-' + list_id).show();
    }
}
// ä¿®æ­£ä»·æ ¼
changePrice = function() {
    var item_id = arguments[0] ? parseInt(arguments[0]) : 0;
    var item_type = arguments[1] ? parseInt(arguments[1]) : 0;

    var itemEvent = $('#goods-number-id-'+item_id).find("input[name='number']");
    var itemNumber = parseInt(itemEvent.val());

    var is_group = $('#ECS_GOODS_ISGROUP').val();

    var buytype = $('#ECS_GOODS_BUYTYPE').val();

    if (item_type == 1) {
        // App.load('m=cart&a=change', {'rec_id':item_id, 'goods_number':itemNumber}, 'POST');
    } else {
        var originalPrice = (is_group == 1 && buytype == 1) ? $('#ECS_GOODS_GROUP').val() : $('#ECS_GOODS_ORIGINAL').val();

        var selectVolume = $('#ECS_GOODS_VOLUME').find("select[name='volumepricelist'] option");
        var volumeFrice = 0;
        if (selectVolume.length) {
            selectVolume.each(function(){
                if (itemNumber >= $(this).val()) {
                    volumeFrice = $(this).text();
                }
            });
        }

        var finalPrice = volumeFrice > 0 ? parseFloat(Math.min(originalPrice,volumeFrice)) : parseFloat(originalPrice);
        //var storage = parseInt($('#ECS_GOODS_STORAGE').html());

        var radioInputs = $('.sku-specs').find('input[type=radio]');
        if (radioInputs.length) {
            for (var i = 0; i < radioInputs.length; i ++ ) {
                if (radioInputs[i].checked) {
                    finalPrice = parseFloat(finalPrice + parseFloat(radioInputs[i].value.split(':')[1]));
                }
            }
        }

        var checkboxInputs = $('.sku-specs').find('input[type=checkbox]');
        if (checkboxInputs.length) {
            for (var j = 0; j < checkboxInputs.length; j ++ ) {
                if (checkboxInputs[j].checked) {
                    finalPrice = parseFloat(finalPrice + parseFloat(checkboxInputs[j].value.split(':')[1]));
                }
            }
        }

        var finalNumber = itemNumber;
        itemEvent.val(finalNumber);

        var integral = $(document.body).find("input[name='integral']");
        if (integral.length) {
            var integral_val = integral.val();
            $('#ECS_GOODS_INTEGRAL').html((integral_val * itemNumber));
            //$('#ECS_GOODS_AMOUNT').html(App.priceFormat(finalPrice - integral_val) + ' + ' + integral_val + 'ç§¯åˆ†');
        } else {
            //$('#ECS_GOODS_AMOUNT').html(App.priceFormat(finalPrice));
        }
        $('.sku-selector-price').html(priceFormat(finalPrice));
        //$('#ECS_GOODS_TOTAL').html(App.priceFormat(finalPrice*finalNumber));
    }
    // ä»·æ ¼æ ¼å¼åŒ–
     function priceFormat(price) {
        return '<span>ï¿¥</span>' + parseFloat(price).toFixed(2);
    }
}
// æ”¯ä»˜æ–¹å¼é€‰æ‹©
paymentSelect = function(elem) {
    if (!$(elem).hasClass('oc-payment-selected')) {
        if ($(elem).hasClass('oc-payment-item-disable')) {
            return;
        }
        var source_val = $(elem).find("input").val();
        $('#oc-payment').find("input[name='payment']").val(source_val);
        $('#oc-payment').find('.oc-payment-selected').removeClass('oc-payment-selected');
        $(elem).addClass('oc-payment-selected');
    }
}